package d0319;

public class EggTest {
    volatile boolean hasEgg=false;

    Thread human=new Thread(()->{
        while (true){
            if (!hasEgg){
                System.out.println("等待");
            }else{
                System.out.println("收获");
                hasEgg=false;
            }
        }
    });

    Thread hen=new Thread(()->{
        while(true){
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            hasEgg=true;
        }
    });

    public static void main(String[] args) {
        EggTest eggTest=new EggTest();
        eggTest.human.start();
        eggTest.hen.start();

    }
}



